// miniprogram/pages/plan/plan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    planList: Object,
    date: null,
    time: null,
    plan: null,
    planOBJ: {date: null, time: null, plan: null},
    planList: Object
  },
  setPlanData(e) {
    var that = this
    this.data.planOBJ.date = e.detail.value.date;
    this.data.planOBJ.time = e.detail.value.time;
    this.data.planOBJ.plan = e.detail.value.plan;
    
    if(!this.data.planOBJ.date || !this.data.planOBJ.time || !this.data.planOBJ.plan) {
      
      wx.showToast({
        title: '请完善数据！',
      })
    }else {

      wx.getStorage({
        key: "_PLANLIST",
        success: res => {
          // 如果里面有数据，就把新的数据存到里面
          let arr = res.data;
          arr.push(that.data.planOBJ)
          wx.setStorage({
            key: "_PLANLIST",
            data: arr
          })        
        },
        fail: res => {
          console.log("fail", res)
          wx.setStorage({
            key: "_PLANLIST",
            data: [that.data.planOBJ,]
          })
        } 
      })
    }
  },
  updateDate(e) {
    this.setData({
      date: e.detail.value
    })
  },
  updateTime(e) {
    this.setData({
      time: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.getStorage({
      key: "_PLANLIST",
      success: res => {
        console.log("res", res)
        that.setData({
          planList: res.data
        })        
      }
    })
    console.log(that.planList)

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})